package com.xdj.controller;

import com.xdj.pojo.Article;
import com.xdj.pojo.PageBean;
import com.xdj.pojo.Result;
import com.xdj.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: ArticleController
 * Package: com.xdj.controller
 * Description:
 *
 * @Author: 信
 * @Create: 2024/1/11 - 16:48
 */
@RestController
@RequestMapping("/article")
public class ArticleController {


    @Autowired
    private ArticleService articleService;

/*    @GetMapping("/list")
    public Result<String> list(){

        return Result.success("文章数据");
    }*/

    /**
     * 新增文章
     * @param article
     * @return
     */
    @PostMapping
    public Result add(@RequestBody @Validated Article article){
        articleService.add(article);
        return Result.success();
    }

    /**
     * 文章列表分页查询
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @param state
     * @return
     */
    @GetMapping
    public Result<PageBean<Article>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer categoryId,
            @RequestParam(required = false) String state
    ){
        PageBean<Article> pageBean = articleService.list(pageNum, pageSize, categoryId, state);
        return Result.success(pageBean);
    }



}
